<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>原型模式</title>
</head>
<body>

</body>
</html>
<script>
  /*
  *方式一：使用Object.create(prototype, optionalDescriptorObjects)
  * */
  // const originalObj = {
  //   model: '保时捷',
  //   fn: function () {
  //     console.log('model:', this.model)
  //   }
  // }

  // const curObj = Object.create(originalObj, {
  //   model: {
  //     value: '嘻哈'
  //   }
  // })
  //
  // curObj.fn()

  /*
  * 使用原型prototype创建
  * */
  const originalObj = {
    init: function (model) {
      this.model = model
    },
    fn: function () {
      console.log('model:', this.model)
    }
  }

  function Car (model) {
    function F () {}
    F.prototype = originalObj
    const f = new F()
    f.init(model)
    return f
  }

  const car = new Car('法拉利')
  car.fn()
</script>